package display;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.springframework.web.context.*;

import domain.ArticuloRepository;
import domain.Articulo;

import util.ArticuloDTO;
import util.ArticuloAssembler;
import util.*;

public class ListaArticulos extends PageController {
  
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
    throws ServletException, IOException {
	  ArticuloRepository articulos = (ArticuloRepository) context.getBean("articuloRepository");
    try {
			Collection lista = articulos.findAllArticulo();
			List data = new ArrayList();
			Iterator itr = lista.iterator();
			while (itr.hasNext()) {
				Articulo prof = (Articulo)itr.next();
				ArticuloDTO dto = ArticuloAssembler.CreateDTO(prof);
				data.add(dto);
			}
      request.setAttribute("articulos",data);
      forward("/listaArticulos.jsp",request,response);
		} catch (Exception e) {
			request.setAttribute("mensaje",e.getMessage());
			forward("/paginaError.jsp",request,response);
		}
  }
}